package cn.jellybmedia.basic.service.impl;

import cn.jellybmedia.basic.mapper.BaseMapper;
import cn.jellybmedia.basic.service.IBaseService;
import cn.jellybmedia.basic.query.BaseQuery;
import cn.jellybmedia.basic.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    public BaseMapper<T> baseMapper;


    /**
     * @Title: loadAll
     * @Description: 查询所有部门数据
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:04
     * @Parameters: []
     * @Return java.util.List<cn.jellybmedia.org.domain.T>
     */
    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 根据id查询部门数据
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:06
     * @Parameters: [id]
     * @Return cn.jellybmedia.org.domain.T
     */
    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: 根据id删除部门
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:07
     * @Parameters: [id]
     * @Return void
     */
    @Override
    @Transactional
    public void remove(Long id) {
        baseMapper.remove(id);
    }

    /**
     * @Title: save
     * @Description: 新增部门
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:08
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);

    }

    /**
     * @Title: update
     * @Description: 修改部门数据
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:08
     * @Parameters: [t]
     * @Return void
     */
    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    /**
     * @Title: queryData
     * @Description: 高级查询与分页查询的方法
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/21 18:08
     * @Parameters: [tQuery]
     * @Return cn.jellybmedia.basic.utils.PageList<cn.jellybmedia.org.domain.T>
     */
    @Override
    public QueryResult<T> queryData(BaseQuery baseQuery) {

        // 1.查询分页总条数
        Integer total = baseMapper.queryCount(baseQuery);

        List<T> rows = baseMapper.queryData(baseQuery);



        return new QueryResult<>(total, rows);
    }

    /**
     * @Title: batchDel
     * @Description: 批量删除
     * @Author: Mr.Zhang
     * @Version: 1.0
     * @Date: 2022/6/26 8:48
     * @Parameters: [ids]
     * @Return void
     */
    @Override
    public void batchDel(Long[] ids) {
        baseMapper.batchDel(ids);
    }

    
}
